home *** CD-ROM | disk | FTP | other *** search
/ Basic Instinct 2 Press Kit / Basic Instinct 2 Press Kit.iso / pc / main.dxr / FlashPaper_1_BIProdNotes.swf / scripts / __Packages / FPUI / SelectableItem.as < prev    next >
Encoding:
Text File  |  2006-03-15  |  4.9 KB  |  176 lines

  1. class FPUI.SelectableItem extends FPUI.Component
  2. {
  3.    var m_labelFieldMC;
  4.    var m_itemNum;
  5.    var m_controller;
  6.    var controller;
  7.    var onPress;
  8.    var m_boldLF = false;
  9.    var m_highlightMC = null;
  10.    var m_lastDrawnColor = FPUI.Component.kWhiteBgColor;
  11.    function SelectableItem()
  12.    {
  13.       var _loc1_ = this;
  14.       super();
  15.       _loc1_.createTextField("m_labelFieldMC",1,0,0,1,1);
  16.       _loc1_.m_labelFieldMC.embedFonts = false;
  17.       _loc1_.m_labelFieldMC.selectable = false;
  18.       _loc1_.m_labelFieldMC.autosize = true;
  19.    }
  20.    function calcLabelHeight(s)
  21.    {
  22.       this.setLabel(s);
  23.       return this.m_labelFieldMC._height;
  24.    }
  25.    function setLabel(label)
  26.    {
  27.       var _loc1_ = this;
  28.       if(_loc1_.m_labelFieldMC.text != label)
  29.       {
  30.          _loc1_.m_labelFieldMC.text = label;
  31.          _loc1_.updateLabelStyle();
  32.       }
  33.    }
  34.    function drawItem(itmObj, selected, index)
  35.    {
  36.       this.displayContent(itmObj,selected,index);
  37.    }
  38.    function getHighlightHeight()
  39.    {
  40.       return this.m_highlightMC._height;
  41.    }
  42.    function doClickHandler()
  43.    {
  44.       this.m_controller.clickHandler(this.m_itemNum);
  45.    }
  46.    function fillHighlight(ca)
  47.    {
  48.       var _loc1_ = this;
  49.       _loc1_.m_highlightMC.clear();
  50.       FPUI.Component.fillRect(_loc1_.m_highlightMC,0,0,_loc1_.m_width,_loc1_.m_height,ca);
  51.    }
  52.    function assignHighlightFunctions(b)
  53.    {
  54.       var _loc2_ = this;
  55.       var _loc1_ = _loc2_.m_highlightMC;
  56.       if(b)
  57.       {
  58.          _loc1_.onPress = function()
  59.          {
  60.             var _loc1_ = this.controller;
  61.             if(_loc1_.getEnabled())
  62.             {
  63.                _loc1_.doClickHandler();
  64.             }
  65.          };
  66.          _loc1_.onDragOver = function()
  67.          {
  68.             var _loc1_ = this.controller;
  69.             if(_loc1_.m_controller.getFocused())
  70.             {
  71.                this.onPress();
  72.             }
  73.          };
  74.          _loc1_.onRollOver = function()
  75.          {
  76.             var _loc1_ = this.controller;
  77.             if(_loc1_.m_controller.hasCursorFocus())
  78.             {
  79.                _loc1_.fillHighlight(FPUI.Component.kRolloverColor);
  80.             }
  81.          };
  82.          _loc1_.onRollOut = function()
  83.          {
  84.             var _loc1_ = this.controller;
  85.             _loc1_.fillHighlight(_loc1_.m_lastDrawnColor);
  86.          };
  87.       }
  88.       else
  89.       {
  90.          _loc1_.onPress = _loc1_.onDragOver = _loc1_.onRollOver = _loc1_.onRollOut = null;
  91.       }
  92.    }
  93.    function setSize(width, height)
  94.    {
  95.       var _loc1_ = this;
  96.       var _loc3_ = width;
  97.       var _loc2_ = -16384;
  98.       _loc1_.m_width = _loc3_;
  99.       _loc1_.m_height = height;
  100.       _loc1_.m_labelFieldMC._x = 2;
  101.       _loc1_.m_labelFieldMC._y = 0;
  102.       _loc1_.m_labelFieldMC._width = _loc3_ - 2;
  103.       if(_loc1_.m_highlightMC == undefined)
  104.       {
  105.          _loc1_.createEmptyMovieClip("m_highlightMC",_loc2_);
  106.          _loc1_.fillHighlight(FPUI.Component.kWhiteBgColor);
  107.          _loc1_.m_highlightMC._x = _loc1_.m_highlightMC._y = 0;
  108.          _loc1_.m_highlightMC.controller = _loc1_;
  109.          _loc1_.m_highlightMC.trackAsMenu = true;
  110.          _loc1_.m_highlightMC.useHandCursor = false;
  111.       }
  112.       _loc1_.m_highlightMC._width = _loc3_;
  113.       _loc1_.m_highlightMC._height = height;
  114.    }
  115.    function setEnabled(enabledFlag)
  116.    {
  117.       var _loc1_ = this;
  118.       if(_loc1_.m_enable != enabledFlag)
  119.       {
  120.          _loc1_.m_enable = enabledFlag;
  121.          _loc1_.updateLabelStyle();
  122.       }
  123.    }
  124.    function setMinHighlightWidth(width)
  125.    {
  126.       this.m_highlightMC._width = Math.max(this.m_width,width);
  127.    }
  128.    function updateLabelStyle()
  129.    {
  130.       var _loc1_ = this;
  131.       if(_loc1_.m_labelFieldMC)
  132.       {
  133.          _loc1_.m_labelFieldMC.setTextFormat(new TextFormat(FlashPaper.Utils.UIFONT,FlashPaper.Utils.UIFONTSIZE,!_loc1_.m_enable ? 8947848 : 0,_loc1_.m_boldLF));
  134.          _loc1_.m_labelFieldMC._height = _loc1_.m_labelFieldMC.textHeight + 2;
  135.       }
  136.    }
  137.    function setLabelBold(bold)
  138.    {
  139.       var _loc1_ = this;
  140.       if(_loc1_.m_boldLF != bold)
  141.       {
  142.          _loc1_.m_boldLF = bold;
  143.          _loc1_.updateLabelStyle();
  144.       }
  145.    }
  146.    function displayContent(itmObj, selected, index)
  147.    {
  148.       var _loc1_ = this;
  149.       var _loc2_ = _loc1_.m_lastDrawnColor;
  150.       if(itmObj)
  151.       {
  152.          _loc1_.setLabel(itmObj.getDataItemLabel() + " ");
  153.          if(selected && _loc1_.m_controller.getFocused())
  154.          {
  155.             _loc2_ = FPUI.Component.kHiliteColor;
  156.          }
  157.          else
  158.          {
  159.             _loc2_ = FPUI.Component.kWhiteBgColor;
  160.          }
  161.          _loc1_.assignHighlightFunctions(true);
  162.       }
  163.       else
  164.       {
  165.          _loc1_.setLabel("");
  166.          _loc2_ = FPUI.Component.kWhiteBgColor;
  167.          _loc1_.assignHighlightFunctions(false);
  168.       }
  169.       if(_loc1_.m_lastDrawnColor != _loc2_)
  170.       {
  171.          _loc1_.m_lastDrawnColor = _loc2_;
  172.          _loc1_.fillHighlight(_loc1_.m_lastDrawnColor);
  173.       }
  174.    }
  175. }
  176.